import { UserProfilesAPI } from "@/request/api";
export default {
  namespaced: true,
  state: {
    userInfo: {
      nickname: "",
      coin: 0,
      headImg: require("@/assets/img/userImg.f8bbec5e.png"),
    },
    cartTotal: 0,
  },
  getters: {},
  mutations: {
    changeUserInfo(state, payload) {
      (state.userInfo = payload.userInfo),
        (state.cartTotal = payload.cartTotal);
    },
    // 初始化信息
    initUserInfo(state, payload) {
      state.userInfo = {
        nickname: "",
        coin: 0,
        headImg: require("@/assets/img/userImg.f8bbec5e.png"),
      };
      state.cartTotal = 0;
    },
  },
  actions: {
    async asyncChangeUserInfo(context) {
      let user = await UserProfilesAPI();
      console.log("user", user.data);
      context.commit("changeUserInfo", user.data);
    },
  },
};
